<?php
namespace Admin\Controller;
use Think\Controller;

class BlogController extends Controller{
    //增加栏目
    public function cadd(){
        if(!IS_POST){
            $this->display();
        }else{
            $cat=D('Cat');
            
            if(!$cat->create()){
                echo $cat->getError();
                exit($cat->getError());
            }else{
                if($cat->add()){
                    $this->redirect('Admin/Blog/clist');
                }else{
                    echo '添加失败';
                }
            }
        }
    }
    
    
    
    //栏目列表
     public function clist(){
         $cat= D('cat');
         $catlist = $cat->select();
         $this->assign('clist',$catlist);
         $this->display();
     }
    
    
    //删除栏目
    public function cdel(){
       $re = D('cat')->delete(I('get.cat_id'));

        if(!$re){
            $this->error('删除失败');
        }else{
            $this->redirect('Admin/Blog/clist');
        }
    }
    
    //编辑栏目
    public function cedi(){
        $cat = D('cat');
        if(!IS_POST){
            $re = $cat->find(I('get.cat_id'));
            $this->assign('info',$re);
            $this->display();
        }else{
           if(!$cat->create()){
               exit($cat->getError());
           } else{
               $cat->where('cat_id='.I('get.cat_id'))->save();
               $this->redirect('Admin/Blog/clist');
           }
        }
    }
    
    
    public function aadd(){
        $this->display();
    }
    
}